//
//  UITableView+Exit.m
//  OpenDoor
//
//  Created by cnmobi on 15/6/6.
//  Copyright (c) 2015年 CNMOBI. All rights reserved.
//

#import "UITableView+Exit.h"

@implementation UITableView(UITableView_Exit)


- (void)setTypeEdge:(UIEdgeInsets)typeEdge
{
    self.separatorInset = typeEdge;
}
- (UIEdgeInsets)typeEdge
{
    return self.separatorInset;
}


- (void)setLineType:(LineType)lineType
{
    if (lineType == TableViewLineTypeAll) {
        self.tableFooterView = [[UIView alloc] init];
        
        self.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
#ifdef __IPHONE_8_0
        
        if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
            
            [self setSeparatorInset:UIEdgeInsetsZero];
            
        }
        
        if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
            if (IOSVersion >= 8.0) {
                [self setLayoutMargins:UIEdgeInsetsZero];
            }
            
        }
#endif
    }
    
    else if(lineType == TableViewLineTypeNone)
    {
        
       self.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    else if(lineType == TableViewLineTypeMine)
    {
        self.tableFooterView = [[UIView alloc] init];
        
        self.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
#ifdef __IPHONE_8_0
        
        if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
            
            [self setSeparatorInset:self.typeEdge];
            
        }
        
        if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
            if (IOSVersion >= 8.0) {
                [self setLayoutMargins:UIEdgeInsetsZero];
            }
            
        }
#endif
    }
    else if(lineType == TableViewLineTypeExit)
    {
        self.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
#ifdef __IPHONE_8_0
        
        if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
            
            [self setSeparatorInset:UIEdgeInsetsZero];
            
        }
        
        if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
            if (IOSVersion >= 8.0) {
                [self setLayoutMargins:UIEdgeInsetsZero];
            }
            
        }
#endif
        
    }
}
- (LineType)lineType
{
    return self.lineType;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
#ifdef __IPHONE_8_0
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsZero];
        
    }
#endif
}

- (void)reloadDataAndisNil:(NSInteger)isNil nitText:(NSString *)textStr
{
    [self reloadData];
    if(isNil==0) {
        if ([self viewWithTag:1234]) {
            return;
        }
        UILabel *label = UILABEL(0, self.sizeHeight*1/3, self.sizeWidth, 40);
        label.text = textStr;
        label.font = FontSize(20);
        label.textColor = [UIColor grayColor];
        label.tag = 1234;
        label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label];
        label = nil;
    }
    else
    {
        if ([self viewWithTag:1234]) {
            UILabel *label = (UILabel *)[self viewWithTag:1234];
            [label removeFromSuperview];
            label = nil;
        }
        
    }
}

- (void)reloadRoomAndisNil:(NSArray *)array nitText:(NSString *)textStr
{
    [self reloadData];
    BOOL isNil = YES;
    int i = 0;
    
    while (i<4)
    {
        NSArray *infoArray = [array objectAtIndex:i];
        if (infoArray.count !=0) {
            isNil = NO;
        }
        i++;
        
    }
    
    if(isNil) {
        if ([self viewWithTag:1234]) {
            return;
        }
        UILabel *label = UILABEL(0, self.sizeHeight*1/3, self.sizeWidth, 40);
        label.text = textStr;
        label.font = FontSize(20);
        label.textColor = [UIColor grayColor];
        label.tag = 1234;
        label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label];
        label = nil;
    }
    else
    {
        if ([self viewWithTag:1234]) {
            UILabel *label = (UILabel *)[self viewWithTag:1234];
            [label removeFromSuperview];
            label = nil;
        }
        
    }
    

}

@end
